﻿var classfruit;
function Fruit(type,score) {

    //Position des fruits
    this.X;
    this.Y;

    classfruit = this;

    this.type = type;
    this.score = score;
    this.fruit = document.getElementById(type);
    this.cote_sprite = null;

    //Etat
    this.ramasse = false;

    this.fruit_img = {
        banane: { src: "images/fruits/banane.png" },
        cerise: { src: "images/fruits/cerise.png" },
        citron: { src: "images/fruits/citron.png" },
        fraise: { src: "images/fruits/fraise.png" },
        mandarine: { src: "images/fruits/mandarine.png" },
        pasteque: { src: "images/fruits/pasteque.png" },
        pomme: { src: "images/fruits/pomme.png" },
        current: { src: "" }
    };

    this.manger = function () {
        this.fruit.parentNode.removeChild(this.fruit);
    }

    this.draw = function () {
        this.fruit.style.left = this.X + "px";
        this.fruit.style.top = this.Y + "px";
    }

    this.init = function (x, y) {
        this.X = x;
        this.Y = y;

        WinJS.Binding.processAll(this.fruit, this.fruit_img.current);
        this.cote_sprite = WinJS.Binding.as(this.fruit_img.current);

        this.cote_sprite.src = this.fruit_img[type].src;

        this.draw();
    }
    this.init(Math.floor((Math.random() * 15)) * 50, Math.floor((Math.random() * 15)) * 50);
}